home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
Statistic.cc,v
< prev
next >
Wrap
Text File
|
1989-05-04
|
6KB
|
323 lines
head 3.3;
branch ;
access ;
symbols ;
locks grunwald:3.3; strict;
comment @@;
3.3
date 89.05.04.14.38.01; author grunwald; state Exp;
branches ;
next 3.2;
3.2
date 89.02.20.15.37.44; author grunwald; state Exp;
branches ;
next 3.1;
3.1
date 88.12.20.13.49.20; author grunwald; state Exp;
branches ;
next 1.2;
1.2
date 88.10.30.13.03.25; author grunwald; state Exp;
branches ;
next 1.1;
1.1
date 88.09.18.16.42.30; author grunwald; state Exp;
branches ;
next ;
desc
@@
3.3
log
@Before switching to Gnu lib version
@
text
@// This may look like C code, but it is really -*- C++ -*-
//
// Copyright (C) 1988 University of Illinois, Urbana, Illinois
//
// written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
//
#include "Statistic.h"
#include "assert.h"
#include <math.h>
void
Statistic::reset()
{
n = 0; x = x2 = 0.0;
maxValue = -MAXFLOAT;
minValue = MAXFLOAT;
}
void
Statistic::operator+=(double value)
{
n ++;
x += value;
x2 += (value * value);
if ( minValue > value) minValue = value;
if ( maxValue < value) maxValue = value;
}
double
Statistic::mean()
{
if ( n > 0) {
return (x / n);
}
else {
return ( 0.0 );
}
}
double
Statistic::var()
{
if ( n > 1) {
return(( x2 - ((x * x) / n)) / ( n - 1));
}
else {
return ( 0.0 );
}
}
double
Statistic::stdDev()
{
if ( n <= 0 || this -> var() <= 0) {
return(0);
} else {
return( (double) sqrt( var() ) );
}
}
int
Statistic::samples()
{
return(n);
}
double
Statistic::min()
{
return(minValue);
}
double
Statistic::max()
{
return(maxValue);
}
double
Statistic::sum()
{
return(x);
}
// t-distribution: given p-value and degrees of freedom, return t-value
// adapted from Peizer & Pratt JASA, vol63, p1416
double
Statistic::tval(double p, int df)
{
double t;
int positive = p >= 0.5;
p = (positive)? 1.0 - p : p;
if (p <= 0.0 || df == 0)
t = HUGE;
else if (p == 0.5)
t = 0.0;
else if (df == 1)
t = 1.0 / tan((p + p) * 1.57079633);
else if (df == 2)
t = sqrt(1.0 / ((p + p) * (1.0 - p)) - 2.0);
else
{
double ddf = df;
double a = sqrt(log(1.0 / (p * p)));
double aa = a * a;
a = a - ((2.515517 + (0.802853 * a) + (0.010328 * aa)) /
(1.0 + (1.432788 * a) + (0.189269 * aa) +
(0.001308 * aa * a)));
t = ddf - 0.666666667 + 1.0 / (10.0 * ddf);
t = sqrt(ddf * (exp(a * a * (ddf - 0.833333333) / (t * t)) - 1.0));
}
return (positive)? t : -t;
}
double
Statistic::confidence(int interval)
{
int samp = samples();
double t = tval(double(100 + interval) * 0.005, samp );
if (t == HUGE)
return t;
else
return (t * stdDev()) / sqrt(double( samp ));
}
double
Statistic::confidence(double p_value)
{
int samp = samples();
double t = tval((1.0 + p_value) * 0.5, samp);
if (t == HUGE)
return t;
else
return (t * stdDev()) / sqrt(double( samp ));
}
void
Statistic::classPrintOn(ostream& st)
{
st << samples() << " " << mean() << " " << stdDev() << " "
<< confidence(90) << " " << confidence(95) << " " << confidence(99);
}
@
3.2
log
@Start using Gnu library heaps for schedulers
@
text
@a10 51
typedef struct tableFormat {
float n;
float parameter[3];
};
//
// The following is Students T-distribution with parameter
// alpha = 0.95 (for 90%)
// = 0.975 (for 95%)
// = 0.995 (for 99%)
//
static const int tableEntries = 35;
static const tableFormat StudentT[ tableEntries ] = {
{ 1, { 6.314, 12.706, 63.657}},
{ 2, { 2.920, 4.303, 9.925}},
{ 3, { 2.353, 3.182, 5.841}},
{ 4, { 2.132, 2.776, 4.604}},
{ 5, { 2.015, 2.571, 4.032}},
{ 6, { 1.943, 2.447, 3.707}},
{ 7, { 1.895, 2.365, 3.499}},
{ 8, { 1.860, 2.306, 3.355}},
{ 9, { 1.833, 2.262, 3.250}},
{ 10, { 1.812, 2.228, 3.169}},
{ 11, { 1.796, 2.201, 3.106}},
{ 12, { 1.782, 2.179, 3.055}},
{ 13, { 1.771, 2.160, 3.012}},
{ 14, { 1.761, 2.145, 2.977}},
{ 15, { 1.753, 2.131, 2.947}},
{ 16, { 1.746, 2.210, 2.921}},
{ 17, { 1.740, 2.110, 2.898}},
{ 18, { 1.734, 2.101, 2.878}},
{ 19, { 1.729, 2.093, 2.861}},
{ 20, { 1.725, 2.086, 2.845}},
{ 21, { 1.721, 2.080, 2.831}},
{ 22, { 1.717, 2.074, 2.819}},
{ 23, { 1.714, 2.069, 2.807}},
{ 24, { 1.711, 2.064, 2.797}},
{ 25, { 1.708, 2.060, 2.787}},
{ 26, { 1.706, 2.056, 2.779}},
{ 27, { 1.703, 2.052, 2.771}},
{ 28, { 1.701, 2.048, 2.763}},
{ 29, { 1.699, 2.045, 2.756}},
{ 30, { 1.697, 2.042, 2.750}},
{ 40, { 1.684, 2.021, 2.704}},
{ 50, { 1.676, 2.009, 2.678}},
{ 75, { 1.665, 1.992, 2.643}},
{ 100, { 1.660, 1.984, 2.626}},
{MAXFLOAT, { 1.645, 1.960, 2.576}}
};
d22 1
a22 1
n += 1;
d61 6
d68 1
a68 1
Statistic::confidence(int interval)
d70 2
a71 1
int index;
d73 5
a77 14
switch( interval ) {
case 90 :
index = 0;
break;
case 95:
index = 1;
break;
case 99:
index = 2;
break;
default :
index = -1;
break;
}
d79 5
a83 1
assert(index >= 0 && index <= 2);
d85 2
a86 3
if (n < 1) {
return(0);
}
d88 27
a114 2
double dn = double(n);
for (int i = 0; dn > StudentT[i].n; i++);
d116 5
a120 2
double meanValue = mean();
double sd = stdDev();
d122 5
a126 2
assert( i >= 0 && i < tableEntries);
double zAlpha = StudentT[i].parameter[index];
d128 9
a136 1
return( (zAlpha * sd) / sqrt( dn ) );
@
3.1
log
@Steay version
@
text
@@
1.2
log
@*** empty log message ***
@
text
@@
1.1
log
@Initial revision
@
text
@d1 6
@